<?php

class Default_Model_Game extends Zend_Db_Table_Abstract
{
    protected $_name = 'game';
    public function getAllData(){
        $query = $this->select()
                        ->from($this->_name)
                        ->order('level DESC')
                        ->order('gameId ASC');
        return $this->fetchAll($query);
    }
    public function addData($gameId, $gameName, $catId, $gameImg, $openDate, $createUser, $createDate, $level, $status){
    	$data = array('gameId' => $gameId, 
                    'gameName' => $gameName, 
                    'catId' => $catId, 
                    'gameImg' => $gameImg, 
                    'openDate' => $openDate, 
                    'createUser' => $createUser, 
                    'level' => $level, 
                    'status' => $status);
        $idAdd = $this->insert($data);
        return $idAdd;
    }
    public function deleteData($gameId){
        $this->delete('gameId = "' . $gameId.'"');
    }
    public function updateData($gameId, $gameName, $catId, $gameImg, $openDate, $repair = '', $level, $status){
    	$data = array('gameName' => $gameName, 
                    'catId' => $catId, 
                    'gameImg' => $gameImg, 
                    'openDate' => $openDate, 
                    'repair' => $repair, 
                    'level' => $level, 
                    'status' => $status);
        return $this->update($data, 'gameId = "' . $gameId.'"');
    }
    public function getDataById($gameId){
    	$query = $this->select()
                        ->from($this->_name)
                        ->where('gameId = ?',$gameId);
        return $this->fetchRow($query);
    }
    public function getDataByGameName($gameName){
    	$query = $this->select()
                        ->from($this->_name)
                        ->where('gameName = ?',$gameName);
        return $this->fetchRow($query);
    }
    public function getDataByGameList($gameList){
        $query = $this->select()
                        ->from(array('g'=>$this->_name))
                        ->where('gameId IN '.$gameList)
                        ->order('level DESC')
                        ->order('gameId ASC');
        return $this->fetchAll($query);
    }

}

























